{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "09166fd1",
   "metadata": {},
   "source": [
    "#### 写出导入pandas的语句，并且给pandas别名为pd。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "154a8dd6",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0eebe1e2",
   "metadata": {},
   "source": [
    "#### 创建一个叫s1的Series，里面包含元素-1.2、3.7、2.5、-8.2、6.3。创建后进行输出。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "91582f72",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0   -1.2\n",
       "1    3.7\n",
       "2    2.5\n",
       "3   -8.2\n",
       "4    6.3\n",
       "dtype: float64"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s1 = pd.Series([-1.2, 3.7, 2.5, -8.2, 6.3])\n",
    "s1"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d1253074",
   "metadata": {},
   "source": [
    "#### 打印s1的所有索引以及所有元素值。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "43bcb273",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "RangeIndex(start=0, stop=5, step=1)\n",
      "[-1.2  3.7  2.5 -8.2  6.3]\n"
     ]
    }
   ],
   "source": [
    "print(s1.index)\n",
    "print(s1.values)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8adf427e",
   "metadata": {},
   "source": [
    "#### 创建一个叫s2的Series，里面包含元素1、2、3、4、5，并且对应索引5、4、3、2、1。创建后进行输出。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "84b9b746",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5    1\n",
       "4    2\n",
       "3    3\n",
       "2    4\n",
       "1    5\n",
       "dtype: int64"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s2 = pd.Series([1, 2, 3, 4, 5], index=[5, 4, 3, 2, 1])\n",
    "s2"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3dd2121d",
   "metadata": {},
   "source": [
    "#### 输出s2里按位置顺序排在第2个的元素。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "e6bbcfde",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s2.iloc[1]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c9ee706c",
   "metadata": {},
   "source": [
    "#### 输出s2里按标签对应从5到3（包括3）范围内的元素。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "4321099a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5    1\n",
       "4    2\n",
       "3    3\n",
       "dtype: int64"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s2.loc[5:3]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7a78f670",
   "metadata": {},
   "source": [
    "#### 通过一个字典来创建Series s3。字典的键为：小李、小陈、小张、小曾、小邓，值为82、93、91、78、68。创建后进行输出。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "094607a0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "小李    82\n",
       "小陈    93\n",
       "小张    91\n",
       "小曾    78\n",
       "小邓    68\n",
       "dtype: int64"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s3 = pd.Series({\"小李\": 82, \"小陈\": 93, \"小张\": 91, \"小曾\": 78, \"小邓\": 68,})\n",
    "s3"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fdb7f56f",
   "metadata": {},
   "source": [
    "#### 把s3里小张标签对应的值改为95，再输出s3。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "c4943339",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "小李    82\n",
       "小陈    93\n",
       "小张    95\n",
       "小曾    78\n",
       "小邓    68\n",
       "dtype: int64"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s3.loc[\"小张\"] = 95\n",
    "s3"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "56662154",
   "metadata": {},
   "source": [
    "#### 输出s3里所有值大于80且小于90的元素。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "930dc23a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "小李    82\n",
       "dtype: int64"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s3[(s3 > 80) & (s3 < 90)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7d77c875-008b-4855-8f17-c15fa45416fa",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
